package com.snail.billing.session;

import com.snail.billing.DataCache;
import com.snail.billing.net.BillingEncode;
import com.snail.billing.net.BillingRegisterArrayHttpSession;
import com.snail.billing.net.BillingSecurity;
import com.snail.billing.util.BillingUtil;

public class RegisterMoblieSession extends BillingRegisterArrayHttpSession {

	public RegisterMoblieSession(String account, String pwd, String captcha) {
		DataCache cache = DataCache.getInstance();
		String host = cache.importParams.hostBusiness;
		String address = String.format("http://%s/ws/register.do?method=sdoMobileRegisterPassport", host);
		setAddress(address);
		addParamPair("smsCode", captcha);
		addBillingPair("userName", BillingEncode.enCode(account, "GBK"));
		addBillingPair("pwd", pwd);
		addBillingPair("email", "woniu@woniu.woniu");
		addBillingPair("gid", cache.importParams.gameId);
		addBillingPair("rid", "0");
		addBillingPair("sid", "0");
		addBillingPair("ip", BillingUtil.getLocalIp());
		addBillingPair("pid", "7");
		addBillingPair("spreaderId", "0");
		addBillingPair("extParams", buildExtra());
		buildParamPair();
	}
	
	private String buildExtra() {
		DataCache cache = DataCache.getInstance();
		String channelId = "SJ";
		if (cache.importParams.extra != null) {
			channelId = cache.importParams.extra.getString("channelId");
		}
		String appVersion = BillingUtil.getAppVersion();
		String deviceId = BillingUtil.getIMEICode();
		String provider = BillingUtil.getProviderName();
		//
		StringBuilder builder = new StringBuilder();
		builder.append("JSON:{\"returnType\":\"json\";\"regFromTypeValue\":\"");
		builder.append(channelId);
		builder.append("|");
		builder.append(appVersion);
		builder.append("|");
		builder.append(deviceId);
		builder.append("|");
		builder.append(provider);
		builder.append("\"}");
		System.out.println(builder.toString());
		return builder.toString();
	}

	@Override
	public BillingSecurity getSecurity() {
		if (DataCache.getInstance().isSandbox) {
			return BillingSecurity.securitySandbox2;
		}
		return BillingSecurity.security;
	}

}
